package com.thirteen.service.impl;

import com.thirteen.dao.ExampleDAO;
import com.thirteen.dao.pojo.ExampleDO;
import com.thirteen.service.ExampleService;
import com.thirteen.service.dto.ExampleDTO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author hhx
 * @since 2020-8-27 23:25:46
 */
@Service
public class ExampleServiceImpl implements ExampleService {

    @Autowired
    private ExampleDAO exampleDAO;

    @Override
    public List<ExampleDTO> getExamplesContains(String keyword, Integer pageNum, Integer pageSize) {
        List<ExampleDTO> dtos = new ArrayList<>();
        for (ExampleDO exampleDO : exampleDAO.findAllByContentContaining(keyword)) {
            ExampleDTO dto = new ExampleDTO();
            //将相同的字段复制
            BeanUtils.copyProperties(exampleDO, dto);
            dtos.add(dto);
        }
        return dtos;
    }
}